<template>
  <div class="global-box">
    <a-form-model
      class="learning"
      ref="ruleForm"
      :model="learningForm"
      :rules="learningFormRules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-model-item label="学习包名称" prop="name" class="w17">
        <a-input
          v-model="learningForm.name"
          :maxLength="inputLength"
          placeholder="请输入学习包名称"
        />
      </a-form-model-item>
      <a-form-model-item label="课程目录" prop="directory" class="w17">
        <a-cascader
          :field-names="{ label: 'value', value: 'id', children: 'children' }"
          :options="directoryOptions"
          :load-data="loadData"
          placeholder="请选择课程目录"
          change-on-select
          v-model="learningForm.directory"
        />
      </a-form-model-item>
      <a-form-model-item label="学习包价格" prop="price" class="w17">
        <a-input
          placeholder="请输入学习包价格"
          @keyup="numbers"
          v-model="learningForm.price"
        ></a-input>
      </a-form-model-item>
      <a-form-model-item label="学习包类型" prop="type">
        <a-radio-group v-model="learningForm.type" @change="typeChange">
          <a-radio :value="item.value" :key="item.value" v-for="item in learningTypeList">{{
            item.label
          }}</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item label="课程内容">
        <span v-for="item in learningTypeList" :key="item.value">
          <a-button
            type="link"
            @click="showModel"
            :value="item.value"
            v-if="learningForm.type === item.value"
          >
            添加{{ item.label }}
          </a-button>
        </span>
        <div v-if="showTable">
          <a-table
            v-if="learningForm.type === 1 && courseData.length > 0"
            :columns="courseColumns"
            :data-source="courseData"
            :pagination="false"
            :scroll="{ y: 450 }"
            :rowKey="record => record.courseId"
          >
            <span slot="action" slot-scope="text, record">
              <template>
                <a @click="handleLook(record)">查看内容</a>
                <a-divider type="vertical" />
                <a @click="handleDelete(record)">删除</a>
              </template>
            </span>
          </a-table>
          <a-table
            v-if="learningForm.type === 2 && notesData.length > 0"
            :columns="notesColumns"
            :data-source="notesData"
            :pagination="false"
            :scroll="{ y: 450 }"
          >
            <span slot="action" slot-scope="text, record">
              <template>
                <a @click="handleDelete(record)">删除</a>
              </template>
            </span>
          </a-table>
          <a-table
            v-if="learningForm.type === 3 && paperData.length > 0"
            :columns="paperColumns"
            :data-source="paperData"
            :pagination="false"
            :scroll="{ y: 450 }"
          >
            <span slot="action" slot-scope="text, record">
              <template>
                <a @click="handleDelete(record)">删除</a>
              </template>
            </span>
          </a-table>
        </div>
      </a-form-model-item>
      <a-form-model-item label="学习包状态" prop="status">
        <a-radio-group v-model="learningForm.status">
          <a-radio :value="item.value" :key="item.value" v-for="item in statusList">{{
            item.label
          }}</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item :wrapper-col="{ span: 15, offset: 4 }">
        <a-button type="primary" @click="onSubmit">提交</a-button>
      </a-form-model-item>
    </a-form-model>
    <view-drawer :dataDrawer="learningData" v-if="learningData.id !== ''" @closeBox="closeBox" />
    <a-modal
      :title="addModel"
      :visible="addVisible"
      @ok="addHandleOk"
      @cancel="addHandleCancel"
      okText="确定"
      cancelText="取消"
      width="50%"
    >
      <div class="form-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="考试类目">
                <a-cascader
                  :field-names="{ label: 'value', value: 'id', children: 'children' }"
                  :options="directoryOptions"
                  :default-value="queryParam.directory"
                  :load-data="loadData"
                  placeholder="请选择考试类目"
                  change-on-select
                  v-model="queryParam.directory"
                  @change="getType"
                />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24" v-if="this.learningForm.type === 1">
              <a-form-item label="课程属性">
                <a-select v-model="queryParam.attr" placeholder="请选择课程属性">
                  <a-select-option :key="item.value" :value="item.value" v-for="item in attrList">{{
                    item.label
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item
                label="课程类型"
                v-if="this.learningForm.type === 1 || this.learningForm.type === 2"
              >
                <a-select v-model="queryParam.type" placeholder="请选择课程类型">
                  <a-select-option
                    :key="item.classTypeId"
                    :value="item.classTypeId"
                    v-for="item in typeList"
                  >
                    {{ item.classTypeName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="课程ID" v-if="this.learningForm.type === 1">
                <a-input placeholder="请输入课程ID" v-model="queryParam.courseId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="讲义标题" v-if="this.learningForm.type === 2">
                <a-input placeholder="请输入讲义标题" v-model="queryParam.notesName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="讲义ID" v-if="this.learningForm.type === 2">
                <a-input placeholder="请输入讲义ID" v-model="queryParam.notesId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="试卷名称" v-if="this.learningForm.type === 3">
                <a-input placeholder="请输入试卷名称" v-model="queryParam.paperName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="试卷ID" v-if="this.learningForm.type === 3">
                <a-input placeholder="请输入试卷ID" v-model="queryParam.paperId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="this.learningForm.type === 3 ? 24 : 16" :sm="24">
              <span class="table-page-search-submitButtons" style="float: right">
                <a-button type="primary" @click="search">筛选</a-button>
                <a-button style="margin-left: 8px" @click="reset">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        :row-selection="rowSelection"
        :columns="addColumns"
        :data-source="addData"
        :pagination="addPagination"
        :rowKey="
          record =>
            this.learningForm.type === 1
              ? record.courseId
              : this.learningForm.type === 2
              ? record.handoutId
              : record.examPaperId
        "
      >
      </a-table>
    </a-modal>
  </div>
</template>
<script>
import { directory, courseList, notesList, paperList, type, add, edit, editCopy, viewContent } from '@/api/product/learning'
import ViewDrawer from '@/views/product/viewDrawer'
const courseColumns = [
  {
    title: '课程ID',
    dataIndex: 'courseId',
    align: 'center'
  },
  {
    title: '课程名称',
    dataIndex: 'courseName',
    align: 'center'
  },
  {
    title: '课程类型',
    dataIndex: 'courseTypeName',
    align: 'center'
  },
  {
    title: '课程属性',
    dataIndex: 'courseAttributeTypeName',
    align: 'center'
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center'
  }
]
const notesColumns = [
  {
    title: '讲义ID',
    dataIndex: 'handoutId',
    align: 'center'
  },
  {
    title: '讲义标题',
    dataIndex: 'handoutName',
    align: 'center'
  },
  {
    title: '年份',
    dataIndex: 'year',
    align: 'center'
  },
  {
    title: '讲义状态',
    dataIndex: 'activeStatus',
    align: 'center'
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center'
  }
]
const paperColumns = [
  {
    title: '试卷ID',
    dataIndex: 'examPaperId',
    align: 'center'
  },
  {
    title: '试卷名称',
    dataIndex: 'examPaperName',
    align: 'center'
  },
  {
    title: '试卷类型',
    dataIndex: 'examPaperTypeName',
    align: 'center'
  },
  {
    title: '试卷状态',
    dataIndex: 'activeStatus',
    align: 'center'
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center'
  }
]
export default {
  components: {
    ViewDrawer
  },
  data () {
    return {
      courseColumns,
      courseData: [],
      notesColumns,
      notesData: [],
      paperColumns,
      paperData: [],
      addColumns: [],
      addData: [],
      learningData: {
        visible: false,
        id: ''
      },
      directoryOptions: [],
      addDirectoryOptions: [],
      inputLength: 20,
      labelCol: { span: 3 },
      wrapperCol: { span: 15 },
      learningForm: {
        name: '',
        directory: [],
        price: '',
        type: 1,
        status: 0
      },
      learningFormRules: {
        name: [
          { required: true, message: '请输入学习包名称', trigger: 'blur' }
        ],
        directory: [{ required: true, message: '请选择课程目录', trigger: 'change' }],
        price: [{ required: true, message: '请输入学习包价格', trigger: 'blur' }],
        type: [{ required: true, message: '请选择学习包类型', trigger: 'change' }],
        status: [{ required: true, message: '请选择学习包状态', trigger: 'change' }]
      },
      showTable: true,
      learningTypeList: [{
        label: '课程',
        value: 1
      }, {
        label: '讲义',
        value: 2
      }, {
        label: '试卷',
        value: 3
      }],
      statusList: [{
        label: '启用',
        value: 0
      }, {
        label: '禁用',
        value: 1
      }],
      attrList: [{
        label: '录播课程',
        value: 1
      }, {
        label: '直播课程',
        value: 2
      }],
      typeList: [],
      addModel: '',
      addVisible: false,
      queryParam: {
        directory: [],
        attr: undefined,
        type: undefined,
        courseId: '',
        notesName: '',
        notesId: '',
        paperName: '',
        paperId: ''
      },
      selectedRowKeys: [],
      selectedRows: [],
      addPagination: {
        current: 1,
        defaultCurrent: 1, // 默认当前页数
        defaultPageSize: 10, // 默认当前页显示数据的大小
        total: 0, // 总数，必须先有
        showSizeChanger: true,
        showQuickJumper: true,
        onShowSizeChange: (current, pageSize) => {
          this.addPagination.current = 1
          this.addPagination.defaultCurrent = 1
          this.addPagination.defaultPageSize = pageSize
          if (this.learningForm.type === 1) {
            this.getCourseList()
          }
          if (this.learningForm.type === 2) {
            this.getNotesList()
          }
          if (this.learningForm.type === 3) {
            this.getPaperList()
          }
        },
        // 改变每页数量时更新显示
        onChange: (current, size) => {
          this.addPagination.current = current
          this.addPagination.defaultCurrent = current
          this.addPagination.defaultPageSize = size
          if (this.learningForm.type === 1) {
            this.getCourseList()
          }
          if (this.learningForm.type === 2) {
            this.getNotesList()
          }
          if (this.learningForm.type === 3) {
            this.getPaperList()
          }
        }
      },
      studyPackageId: ''
    }
  },
  computed: {
    rowSelection () {
      const that = this
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: (selectedRowKeys, selectedRows) => {
          that.selectedRowKeys = selectedRowKeys
        },
        onSelectAll: (isSelected, selectedRows, changedRows) => {
          if (isSelected) {
            that.selectedRows = [...that.selectedRows, ...selectedRows]
          } else {
            const removedIds = changedRows.map(i => i.courseId)
            that.selectedRows = that.selectedRows.filter(i => !removedIds.includes(i.courseId))
          }
        },
        onSelect: (record, isSelected) => {
          if (isSelected) {
            that.selectedRows.push(record)
          } else {
            that.selectedRows = that.selectedRows.filter(i => i.courseId !== record.courseId)
          }
        },
        getCheckboxProps: (record) => ({
          props: {
            checked: that.selectedRowKeys.indexOf(record.courseId) > -1
          }
        })
      }
    }
  },
  mounted () {
    this.getDirectory()
    this.addGetDirectory()
    if (this.$route.params.studyPackageId && this.$route.params.studyPackageId !== '') {
      this.studyPackageId = this.$route.params.studyPackageId
      this.getLearningInfo()
    }
  },
  methods: {
    closeBox (v) {
      this.learningData = {
        visible: false,
        id: ''
      }
    },
    // 限制排序只能输入数字
    numbers () {
      this.learningForm.price = this.learningForm.price.replace(/\D/g, '')
    },
    // 查看内容
    handleLook (record) {
      this.learningData.visible = true
      this.learningData.id = record.courseId
    },
    // 学习包类型切换
    typeChange (e) {
      this.learningForm.type = e.target.value
      this.selectedRows = []
      if (this.$route.params.edit) {
        return false
      }
      this.courseData = []
      this.notesData = []
      this.paperData = []
    },
    getLearningInfo () {
      const data = {
        studyPackageId: this.studyPackageId
      }
      editCopy(data).then(res => {
        if (res.code === '1') {
          this.learningForm = {
            price: res.data.studyPackagePrice,
            name: res.data.studyPackageName,
            type: res.data.studyPackageType,
            status: res.data.activeStatus,
            directory: []
          }
          this.learningForm.directory[0] = res.data.directoryId
          this.learningForm.directory[1] = res.data.examId
          this.learningForm.directory[2] = res.data.subjectId
          this.learningForm.directory[3] = res.data.fourExamId
          this.learningForm.directory[4] = res.data.fiveExamId
          this.learningForm.directory[5] = res.data.sixExamId
          this.learningForm.directory = this.learningForm.directory.filter(item => {
            return item !== 0
          })
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
      viewContent(data).then(res => {
        if (res.code === '1') {
          console.log(res)
          if (res.data.studyPackageType === 1) {
            this.addData = res.data.courseListDTOS
          }
          if (res.data.studyPackageType === 1) {
            this.courseColumns = [
              {
                title: '课程ID',
                dataIndex: 'courseId',
                align: 'center'
              },
              {
                title: '课程名称',
                dataIndex: 'courseName',
                align: 'center'
              },
              {
                title: '课程类型',
                dataIndex: 'courseTypeName',
                align: 'center'
              },
              {
                title: '课程属性',
                dataIndex: 'courseAttributeTypeName',
                align: 'center'
              },
              {
                title: '操作',
                dataIndex: 'action',
                scopedSlots: { customRender: 'action' },
                align: 'center'
              }
            ]
            this.courseData = res.data.courseListDTOS
          }
          if (res.data.studyPackageType === 2) {
            this.notesColumns = [
              {
                title: '讲义ID',
                dataIndex: 'handoutId',
                align: 'center'
              },
              {
                title: '讲义标题',
                dataIndex: 'handoutName',
                align: 'center'
              },
              {
                title: '年份',
                dataIndex: 'year',
                align: 'center'
              },
              {
                title: '讲义状态',
                dataIndex: 'activeStatus',
                align: 'center'
              }
            ]
            this.notesData = res.data.handoutContentDTOS
          }
          if (res.data.studyPackageType === 3) {
            this.paperColumns = [
              {
                title: '试卷ID',
                dataIndex: 'examPaperId',
                align: 'center'
              },
              {
                title: '试卷名称',
                dataIndex: 'examPaperName',
                align: 'center'
              },
              {
                title: '试卷类型',
                dataIndex: 'examPaperTypeName',
                align: 'center'
              },
              {
                title: '试卷状态',
                dataIndex: 'activeStatus',
                align: 'center'
              }
            ]
            this.paperData = res.data.examPaperContentDTOS
          }
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    onSubmit () {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.onSubmitData()
        } else {
          return false
        }
      })
    },
    onSubmitData () {
      const data = {
        studyPackageId: this.studyPackageId,
        studyPackageName: this.learningForm.name,
        studyPackagePrice: Number(this.learningForm.price),
        studyPackageType: this.learningForm.type,
        activeStatus: this.learningForm.status,
        directoryId: this.learningForm.directory[0]
      }
      const idList = []
      if (this.learningForm.type === 1) {
        this.courseData.forEach(item => {
          idList.push(item.courseId)
        })
      }
      if (this.learningForm.type === 2) {
        this.notesData.forEach(item => {
          idList.push(item.handoutId)
        })
      }
      if (this.learningForm.type === 3) {
        this.paperId.forEach(item => {
          idList.push(item.courseId)
        })
      }
      data.contentId = idList.join()
      if (this.learningForm.directory[1] && this.learningForm.directory[1] !== '') {
        data.examId = this.learningForm.directory[1]
      }
      if (this.learningForm.directory[2] && this.learningForm.directory[2] !== '') {
        data.subjectId = this.learningForm.directory[2]
      }
      if (this.learningForm.directory[3] && this.learningForm.directory[3] !== '') {
        data.fourExamId = this.learningForm.directory[3]
      }
      if (this.learningForm.directory[4] && this.learningForm.directory[4] !== '') {
        data.fiveExamId = this.learningForm.directory[4]
      }
      if (this.learningForm.directory[5] && this.learningForm.directory[5] !== '') {
        data.sixExamId = this.learningForm.directory[5]
      }
      if (idList.length === 0) {
        this.$message.error('请添加课程内容')
        return false
      }
      if (this.$route.params.edit) {
        edit(data).then(res => {
          if (res.code === '1') {
            this.$router.push({
              name: 'learningPackage'
            })
          } else {
            this.$message.error(res.msg)
          }
        }).catch(err => {
          this.$message.error(err.msg)
        })
      } else {
        add(data).then(res => {
          if (res.code === '1') {
            this.$router.push({
              name: 'learningPackage'
            })
          } else {
            this.$message.error(res.msg)
          }
        }).catch(err => {
          this.$message.error(err.msg)
        })
      }
    },
    // 课程内容弹出框
    showModel () {
      if (this.learningForm.type === 1) {
        this.addModel = '添加课程'
        this.addColumns = [
          {
            title: '课程ID',
            dataIndex: 'courseId',
            align: 'center'
          },
          {
            title: '课程名称',
            dataIndex: 'courseName',
            align: 'center'
          },
          {
            title: '课程类型',
            dataIndex: 'courseTypeName',
            align: 'center'
          },
          {
            title: '课程属性',
            dataIndex: 'courseAttributeTypeName',
            align: 'center'
          }
        ]
        this.getCourseList()
      }
      if (this.learningForm.type === 2) {
        this.addModel = '添加讲义'
        this.addColumns = [
          {
            title: '讲义ID',
            dataIndex: 'handoutId',
            align: 'center'
          },
          {
            title: '讲义标题',
            dataIndex: 'handoutName',
            align: 'center'
          },
          {
            title: '年份',
            dataIndex: 'year',
            align: 'center'
          },
          {
            title: '讲义状态',
            dataIndex: 'activeStatus',
            align: 'center'
          }
        ]
        this.getNotesList()
      }
      if (this.learningForm.type === 3) {
        this.addModel = '添加试卷'
        this.addColumns = [
          {
            title: '试卷ID',
            dataIndex: 'examPaperId',
            align: 'center'
          },
          {
            title: '试卷名称',
            dataIndex: 'examPaperName',
            align: 'center'
          },
          {
            title: '试卷类型',
            dataIndex: 'examPaperTypeName',
            align: 'center'
          },
          {
            title: '试卷状态',
            dataIndex: 'activeStatus',
            align: 'center'
          }
        ]
        this.getPaperList()
      }
    },
    // 弹出框确定
    addHandleOk () {
      if (this.selectedRows.length === 0) {
        this.$message.error('请选择课程内容')
        return false
      }
      if (this.learningForm.type === 1) {
        const course = []
        this.courseData.forEach(item => {
          course.push(item.courseId)
        })
        this.selectedRows.forEach(item => {
          if (!course.includes(item.courseId)) {
            this.courseData.push(item)
          }
        })
      }
      if (this.learningForm.type === 2) {
        const notes = []
        this.notesData.forEach(item => {
          notes.push(item.handoutId)
        })
        this.selectedRows.forEach(item => {
          if (!notes.includes(item.handoutId)) {
            this.notesData.push(item)
          }
        })
      }
      if (this.learningForm.type === 3) {
        const paper = []
        this.paperData.forEach(item => {
          paper.push(item.examPaperId)
        })
        this.selectedRows.forEach(item => {
          if (!paper.includes(item.examPaperId)) {
            this.paperData.push(item)
          }
        })
      }
      this.selectedRowKeys = []
      this.selectedRows = []
      this.addVisible = false
    },
    // 弹出框取消
    addHandleCancel () {
      this.queryParam = {
        directory: [],
        attr: undefined,
        type: undefined,
        courseId: '',
        notesName: '',
        notesId: '',
        paperName: '',
        paperId: ''
      }
      this.addPagination.current = 1
      this.addPagination.defaultCurrent = 1
      this.selectedRowKeys = []
      this.selectedRows = []
      this.addVisible = false
    },
    // 删除
    handleDelete (re) {
      if (this.learningForm.type === 1) {
        this.courseData = this.courseData.filter(item => {
          return item.courseId !== re.courseId
        })
      }
      if (this.learningForm.type === 2) {
        this.notesData = this.notesData.filter(item => {
          return item.handoutId !== re.handoutId
        })
      }
      if (this.learningForm.type === 3) {
        this.paperData = this.paperData.filter(item => {
          return item.examPaperId !== re.examPaperId
        })
      }
    },
    // 筛选
    search () {
      if (this.learningForm.type === 1) {
        this.getCourseList()
      }
      if (this.learningForm.type === 2) {
        this.getNotesList()
      }
      if (this.learningForm.type === 3) {
        this.getPaperList()
      }
    },
    // 重置
    reset () {
      this.queryParam = {
        directory: [],
        attr: undefined,
        type: undefined,
        courseId: '',
        notesName: '',
        notesId: '',
        paperName: '',
        paperId: ''
      }
      if (this.learningForm.type === 1) {
        this.getCourseList()
      }
      if (this.learningForm.type === 2) {
        this.getNotesList()
      }
      if (this.learningForm.type === 3) {
        this.getPaperList()
      }
    },
    // 添加课程列表
    getCourseList () {
      const data = {
        currentPage: this.addPagination.defaultCurrent,
        pageSize: this.addPagination.defaultPageSize
      }
      if (this.queryParam.status !== '') {
        data.activeStatus = this.queryParam.status
      }
      if (this.queryParam.attr !== '') {
        data.courseAttributeType = this.queryParam.attr
      }
      if (this.queryParam.type !== '') {
        data.courseTypeId = this.queryParam.type
      }
      if (this.queryParam.id !== '') {
        data.courseId = this.queryParam.id
      }
      if (this.queryParam.directory[0]) {
        data.directoryId = this.queryParam.directory[0]
      }
      if (this.queryParam.directory[1]) {
        data.examId = this.queryParam.directory[1]
      }
      if (this.queryParam.directory[2]) {
        data.subjectId = this.queryParam.directory[2]
      }
      if (this.queryParam.directory[3]) {
        data.fourExamId = this.queryParam.directory[3]
      }
      if (this.queryParam.directory[4]) {
        data.fiveExamId = this.queryParam.directory[4]
      }
      if (this.queryParam.directory[5]) {
        data.sixExamId = this.queryParam.directory[5]
      }
      courseList(data).then(res => {
        if (res.code === '1') {
          this.addPagination.total = res.data.totalSize
          this.addData = res.data.rows
          this.addVisible = true
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    // 添加讲义列表
    getNotesList () {
      const data = {
        currentPage: this.addPagination.defaultCurrent,
        pageSize: this.addPagination.defaultPageSize
      }
      if (this.queryParam.notesName !== '') {
        data.handoutName = this.queryParam.notesName
      }
      if (this.queryParam.notesId !== '') {
        data.handoutId = this.queryParam.notesId
      }
      if (this.queryParam.directory[0]) {
        data.directoryId = this.queryParam.directory[0]
      }
      if (this.queryParam.directory[1]) {
        data.examId = this.queryParam.directory[1]
      }
      if (this.queryParam.directory[2]) {
        data.subjectId = this.queryParam.directory[2]
      }
      if (this.queryParam.directory[3]) {
        data.fourExamId = this.queryParam.directory[3]
      }
      if (this.queryParam.directory[4]) {
        data.fiveExamId = this.queryParam.directory[4]
      }
      if (this.queryParam.directory[5]) {
        data.sixExamId = this.queryParam.directory[5]
      }
      notesList(data).then(res => {
        if (res.code === '1') {
          this.addPagination.total = res.data.totalSize
          this.addData = res.data.rows
          this.addVisible = true
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    // 添加试卷列表
    getPaperList () {
      const data = {
        currentPage: this.addPagination.defaultCurrent,
        pageSize: this.addPagination.defaultPageSize
      }
      if (this.queryParam.paperName !== '') {
        data.paperName = this.queryParam.paperName
      }
      if (this.queryParam.paperId !== '') {
        data.paperId = this.queryParam.paperId
      }
      if (this.queryParam.directory[0]) {
        data.directoryId = this.queryParam.directory[0]
      }
      if (this.queryParam.directory[1]) {
        data.examId = this.queryParam.directory[1]
      }
      if (this.queryParam.directory[2]) {
        data.subjectId = this.queryParam.directory[2]
      }
      if (this.queryParam.directory[3]) {
        data.fourExamId = this.queryParam.directory[3]
      }
      if (this.queryParam.directory[4]) {
        data.fiveExamId = this.queryParam.directory[4]
      }
      if (this.queryParam.directory[5]) {
        data.sixExamId = this.queryParam.directory[5]
      }
      paperList(data).then(res => {
        if (res.code === '1') {
          this.addPagination.total = res.data.totalSize
          this.addData = res.data.rows
          this.addVisible = true
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    // 获取课程目录
    getDirectory () {
      const data = {
        type: 0,
        directoryLevel: 1
      }
      directory(data).then(res => {
        if (res.code === '1') {
          res.data.forEach(item => {
            item.isLeaf = false
          })
          this.directoryOptions = res.data
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    // 课程目录二级-六级
    loadData (selectedOptions) {
      const targetOption = selectedOptions[selectedOptions.length - 1]
      const data = {
        type: 1,
        parentId: targetOption.id,
        directoryLevel: 2
      }
      targetOption.loading = true
      directory(data).then(res => {
        if (res.code === '1') {
          if (res.data.length > 0) {
            res.data.forEach(item => {
              item.isLeaf = false
            })
            targetOption.loading = false
            targetOption.children = [...res.data]
          } else {
            targetOption.loading = false
            this.$message.error('暂无更多数据')
          }
        } else {
          targetOption.loading = false
          this.$message.error(res.msg)
        }
        this.directoryOptions = [...this.directoryOptions]
      }).catch(err => {
        this.$message.error(err.msg)
        targetOption.loading = false
      })
    },
    // 获取课程类型
    getType () {
      if (this.queryParam.directory.length === 0) {
        this.typeList = []
        this.queryParam.type = undefined
        return false
      }
      if (!this.queryParam.directory[1]) {
        return false
      }
      if (this.oldExamId === this.queryParam.directory[1]) {
        return false
      }
      const data = {
        examId: this.queryParam.directory[1]
      }
      type(data).then(res => {
        if (res.code === '1') {
          this.typeList = res.data
          this.queryParam.type = undefined
          this.oldExamId = this.queryParam.directory[1]
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    // 获取课程目录
    addGetDirectory () {
      const data = {
        type: 0,
        directoryLevel: 1
      }
      directory(data).then(res => {
        if (res.code === '1') {
          res.data.forEach(item => {
            item.isLeaf = false
          })
          this.addDirectoryOptions = res.data
        }
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    // 课程目录二级-六级
    addLoadData (selectedOptions) {
      const targetOption = selectedOptions[selectedOptions.length - 1]
      const data = {
        type: 1,
        parentId: targetOption.id,
        directoryLevel: 2
      }
      targetOption.loading = true
      directory(data).then(res => {
        if (res.code === '1') {
          if (res.data.length > 0) {
            res.data.forEach(item => {
              item.isLeaf = false
            })
            targetOption.loading = false
            targetOption.children = [...res.data]
          } else {
            targetOption.loading = false
            this.$message.error('暂无更多数据')
          }
        } else {
          targetOption.loading = false
          this.$message.error(res.msg)
        }
        this.addDirectoryOptions = [...this.addDirectoryOptions]
      }).catch(err => {
        this.$message.error(err.msg)
        targetOption.loading = false
      })
    }
  }
}
</script>
<style lang="less" scoped>
.learning {
  margin-top: 40px;
}
</style>
<style lang="less">
.w17 {
  .ant-col-15 {
    width: 18%;
  }
}
</style>
